home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1989 / 05 / send.c < prev    next >
Text File  |  1989-07-19  |  1KB  |  47 lines

  1.  
  2. typedef int (*funcp)();
  3.  
  4. typedef struct METH_T {
  5.     int    msg;                 // msg on top to improve compare time
  6.     funcp  procc;               // pointer to method for msg
  7.     struct METH_T near *next;   // next entry in this hash chain
  8.     } METH_TABLE;               // entry in method table
  9.  
  10. #define MAX_METHS 32            // must be multi of 2
  11. typedef struct class_def {
  12.     METH_TABLE near *tbl;       // pointer to method table for this class
  13.     char       *name;           // asciiz string of class name
  14.     int        size;            // size of objects in this class
  15.     struct class_def  *super;   
  16.     METH_TABLE near *hash[MAX_METHS]; // hash table for method look-ups
  17.     } CLASS_DEF;
  18.  
  19. typedef struct {
  20.     CLASS_DEF near *class;
  21.     } *Obj_x;
  22.  
  23. /*---------------------------------------------------*/
  24. void *send(obj,msg)
  25. Obj_x obj;
  26. int msg;
  27. {
  28.     METH_TABLE  near *tbl;
  29.     CLASS_DEF    near *clas;
  30.     int hash;
  31.  
  32.     hash=msg & (MAX_METHS-1);
  33.  
  34.     clas=obj->class;
  35.     if ( !(tbl=clas->hash[hash]) ) {
  36.         send_org(clas);                     // initialize the hash table
  37.         tbl=clas->hash[hash];
  38.         }
  39.  
  40.     while (tbl->msg != msg)                 // search hash chain for msg
  41.         tbl=tbl->next;
  42.  
  43.     (*tbl->procc)();                        // NOTE:
  44.                                             //  need to convert this to a jump
  45.     return;
  46. }
  47.